package com.hxit.contorller;


import com.hxit.pojo.Result;
import com.hxit.pojo.User;
import com.hxit.servics.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    //新增用户信息
    @PostMapping("/InsertUser")
    public Result InsertUser(@RequestBody User user){
        userService.insertUser(user);
        log.info("添加用户");
        return Result.success();
    }


    //查询用户
    @GetMapping("/FindById/{id}")
    public Result FindById(@PathVariable Integer id){
        User user = userService.FindById(id);
        log.info("根据id查询用户{}",user);
        return Result.success(user);
    }

    //修改用户
    @PutMapping("/UpdateUser")
    public Result UpdateUser(@RequestBody User user){
        userService.UpdateUser(user);
        log.info("修改用户信息");
        return Result.success();
    }

    //删除用户
    @DeleteMapping("/DeleteUser/{ids}")
    public Result DeleteUser(@PathVariable List<Integer> ids){
        userService.DeleteUser(ids);
        log.info("删除用户");
        return Result.success();
    }
}